﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CCL.SocketMessage
{
    /// <summary>
    /// SocketMessage의 여러 상수를 제공합니다.
    /// </summary>
    public static class Constant
    {
        /// <summary>
        /// 단편화가 되었는지 설정합니다.
        /// </summary>
        public enum Fragmented
        {
            Yes,
            No
        }

        /// <summary>
        /// 마지막 메시지인지 설정합니다.
        /// </summary>
        public enum LastMsg
        {
            Yes,
            No
        }

        /// <summary>
        /// 결과를 설정합니다.
        /// </summary>
        public enum Result
        {
            Success,
            Fail
        }

        /// <summary>
        /// Header Type을 설정합니다.
        /// </summary>
        public enum HeaderType
        {
            Requst,
            Response
        }

        public enum Permission
        {
            Update = 0x01,
            Commit = 0x02,
            Admin = 0x04,
            All = Update | Commit | Admin
        }

        /// <summary>
        /// 각종 변수의 Size를 규정하는 Class를 제공합니다.
        /// </summary>
        public static class Length
        {
            /// <summary>
            /// E-Mail 주소의 최대길이
            /// </summary>
            public const int Email = 30;

            /// <summary>
            /// Password의 최대길이
            /// </summary>
            public const int Password = 30;

            /// <summary>
            /// 이름의 최대길이
            /// </summary>
            public const int Name = 30;

            /// <summary>
            /// Error Message의 최대길이
            /// </summary>
            public const int ErrorMessage = 100;

            /// <summary>
            /// 날짜의 최대길이
            /// </summary>
            public const int Date = 24;

            /// <summary>
            /// 프로젝트 이름의 최대길이
            /// </summary>
            public const int ProjectName = 30;

            /// <summary>
            /// 로그 메시지의 최대길이
            /// </summary>
            public const int Log = 500;

            /// <summary>
            /// 파일이름의 최대 길이
            /// </summary>
            public const int FileName = 256;
        }

        // [추가시 수정 必]
        /// <summary>
        /// Body Type을 규정합니다.
        /// </summary>
        public enum BodyType
        {
            TypeError,
            Login,
            Join,
            RegistProject,
            GetProjectList,
            GetProjectMemberList,
            RegistProjectMemberList,
            FileDownload,
            FileDownloadReady,          // only Response Packet
            CheckOutProject,            // only Request Packet
            FileUpload,
            FileDelete,                 // only Request Packet
            CommitProject,
            UpdateProject,              // only Request Packet
            ShowLog,
            // 미구현
        }

        // [추가시 수정 必]
        /// <summary>
        /// Message의 Body객체를 통해 BodyType을 가져옵니다.
        /// </summary>
        /// <param name="body">확인하고자 하는 Message의 Body</param>
        /// <returns>Body의 Type</returns>
        public static BodyType TypeConverter(ISerializable body)
        {
            BodyType type = BodyType.TypeError;

            if (body is Request.Login || body is Response.Login)
                type = BodyType.Login;
            else if (body is Request.Join || body is Response.Join)
                type = BodyType.Join;
            else if (body is Request.RegistProject || body is Response.RegistProject)
                type = BodyType.RegistProject;
            else if (body is Request.GetProjectList || body is Response.GetProjectList)
                type = BodyType.GetProjectList;
            else if (body is Request.GetProjectMemberList || body is Response.GetProjectMemberList)
                type = BodyType.GetProjectMemberList;
            else if (body is Request.RegistProjectMemberList || body is Response.RegistProjectMemberList)
                type = BodyType.RegistProjectMemberList;
            else if (body is Request.FileDownload || body is Response.FileDownload)
                type = BodyType.FileDownload;
            else if (body is Request.CheckOutProject)
                type = BodyType.CheckOutProject;
            else if (body is Response.FileDownloadReady)
                type = BodyType.FileDownloadReady;
            else if (body is Request.FileUpload || body is Response.FileUpload)
                type = BodyType.FileUpload;
            else if (body is Request.FileDelete)
                type = BodyType.FileDelete;
            else if (body is Request.CommitProject || body is Response.CommitProject)
                type = BodyType.CommitProject;
            else if (body is Request.UpdateProject)
                type = BodyType.UpdateProject;
            else if (body is Request.ShowLog || body is Response.ShowLog)
                type = BodyType.ShowLog;

            // 미구현

            return type;
        }
    }
}
